<?php

use Illuminate\Database\Seeder;

use Silber\Bouncer\BouncerFacade;

class BouncerSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        BouncerFacade::role()->firstOrCreate([
            'name' => 'superadmin',
            'title' => '超级管理员',
        ]);

        BouncerFacade::role()->firstOrCreate([
            'name' => 'admin',
            'title' => '管理员',
        ]);
        BouncerFacade::allow('superadmin')->everything();

//        BouncerFacade::allow('admin')->everything();
        $this->initAbility();
    }

    public function initAbility()
    {
        $backstage = config('authority.backstage');
        foreach ($backstage as $item) {
            BouncerFacade::ability()->firstOrCreate([
                'name' => $item['ability'],
                'title' => $item['name'],
            ]);
        }
        BouncerFacade::refresh();
    }
}
